<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*-------------------------------------------------------
 *缓存类
 *用于缓存数据库里系统必须的信息
 *此类信息通常为长期不需要更换的
 *-------------------------------------------------------
 */
require_once APPPATH."/libraries/email/class.phpmailer.php"; //下载的文件必须放在该文件所在目录
include(APPPATH."/libraries/email/class.smtp.php");
class Email extends PHPMailer{
	private $CI;
	private $to; //接受者邮箱
	public function __construct()
	{
		parent::__construct();
		$this->CI =& get_instance();
		$this->CI->config->load('my_email');
		$this->IsSMTP(); // 使用SMTP方式发送
		$this->CharSet=$this->CI->config->item('charset');// 设置邮件的字符编码
		$this->Host = $this->CI->config->item('smtp_host'); // 您的企业邮局域名
		$this->SMTPAuth = $this->CI->config->item('SMTPAuth'); // 启用SMTP验证功能
		$this->Username = $this->CI->config->item('smtp_user'); // 邮局用户名(请填写完整的email地址)
		$this->Password = $this->CI->config->item('smtp_pass'); // 邮局密码
		$this->SetFrom = $this->CI->config->item('smtp_email_user'); //邮件发送者email地址
		$this->FromName = $this->CI->config->item('fromname');
		$this->Port = $this->CI->config->item('smtp_port');
		//$this->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件 　　//
		$this->IsHTML($this->CI->config->item('mailtype')); // set email format to HTML //是否使用HTML格式
		$this->SetFrom($this->CI->config->item('smtp_email_user'), $this->CI->config->item('url'));

	}
	//获取收件人
	//param $data收件人地址
	//param  $names 收件人名称
	public function getTo($data,$names = '亲')
	{

		$this->AddAddress($data,$names);//收件人地址，可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名") 　　//$this->AddReplyTo("", "");
	}
	//获取附件
	//param $data 附件信息
	//return
	public function addAttachment($data)
	{
		$this->AddAttachment($data); // 添加附件
	}
	//获取邮件标题
	//param $data 邮件标题
	//return 
	public function getSubject($data)
	{
		$this->Subject = $data; //邮件标题
	}
	//获取邮件内容
	//param $data 邮件内容
	//return
	public function getBody($data)
	{
		$this->Body = $data; //邮件内容
	}

	public function main(){
			if(!$this->Send())
			{
				return false;
			}
			return true;
		}

	}